I have the following struct that holds the basic data for setting up my window/directx. Everything works good except for my
Here is the struct file if it is needed.Code:LPDIRECT3DDEVICE9 d3DDev;
I haven't set up the Direct input devices yet, but this function initiates everything.Code:#pragma once #include <windows.h> #include <windowsx.h> #include <d3d9.h> #include <d3dx9.h> #include <dinput.h> typedef struct sWindowData { sWindowData() { ZeroMemory(&wClass, sizeof(WNDCLASSEX)); iWidth/*--*/= 0; iHeight/*-*/= 0; fFullscreen = FALSE; d3D/*-----*/= 0; d3DDev/*--*/= 0; dInKeyboard = 0; dInMouse/**/= 0; }; /*********/ /*Windows*/ /*********/ //Window class WNDCLASSEX wClass; //Window Handle HWND hWnd; //The window message struct MSG sMsg; //hInstance handle HINSTANCE hInstance; //Window Size DWORD iWidth; DWORD iHeight; //Is application fullscreen? BOOL fFullscreen; /*********/ /*DirectX*/ /*********/ // the pointer to our Direct3D interface LPDIRECT3D9 d3D; // the pointer to the device class LPDIRECT3DDEVICE9 d3DDev; // the pointer to the keyboard device LPDIRECTINPUTDEVICE8 dInKeyboard; // the pointer to the mouse device LPDIRECTINPUTDEVICE8 dInMouse; }sWindowData;
The highlighted(red) text throws an error in the debugger. sData->d3DDev is still 0.Code://Iniatiate BOOL cWindow::Initialize(HINSTANCE& hInstance, int p_iWidth, int p_iHeight, BOOL p_fFullscreen) { //Create sData structure sData = new sWindowData(); if (!sData) { std::stringstream text; std::stringstream caption; text << "Error: Could not allocate memory.\n" << " - Failed to allocate sData structure."; caption << "cWindow: " << this << " Error"; MessageBoxA(0,text.str().c_str(),caption.str().c_str(), MB_OK|MB_ICONERROR); exit(1); } //Set sData variables required sData->hInstance = hInstance; sData->iWidth = p_iWidth; sData->iHeight = p_iHeight; sData->fFullscreen = p_fFullscreen; //Set window class variables sData->wClass.cbSize = sizeof(WNDCLASSEX); sData->wClass.style = CS_CLASSDC; sData->wClass.lpfnWndProc = (WNDPROC)WindowProc; sData->wClass.hInstance = sData->hInstance; sData->wClass.hCursor = LoadCursor(NULL, IDC_ARROW); sData->wClass.lpszClassName = "GameClass"; //Register the window class RegisterClassEx(&sData->wClass); //Create the window /**** TODO: ENABLE Fullscreen/Windowed toggle ****/ sData->hWnd = CreateWindowEx( NULL, "GameClass", "Our Direct3D Program", WS_OVERLAPPEDWINDOW, 0, 0, sData->iWidth, sData->iHeight, NULL, NULL, sData->hInstance, NULL); sData->d3D = Direct3DCreate9(D3D_SDK_VERSION); if (!sData->d3D) { std::stringstream text; std::stringstream caption; text << "Error: Could not initiate Direct3D9."; caption << "cWindow: " << this << " Error"; MessageBoxA(0,text.str().c_str(),caption.str().c_str(), MB_OK|MB_ICONERROR); delete sData; exit(1); } D3DPRESENT_PARAMETERS d3dpp; ZeroMemory(&d3dpp, sizeof(d3dpp)); /**** TODO: ENABLE Fullscreen/Windowed toggle ****/ d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.hDeviceWindow = sData->hWnd; d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; d3dpp.BackBufferWidth = sData->iWidth; d3dpp.BackBufferHeight = sData->iHeight; d3dpp.EnableAutoDepthStencil = TRUE; d3dpp.AutoDepthStencilFormat = D3DFMT_D16; // create a device class using this information and the info from the d3dpp stuct sData->d3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, sData->hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &sData->d3DDev); // turn off the 3D lighting sData->d3DDev->SetRenderState(D3DRS_LIGHTING, FALSE); // turn on the z-buffer sData->d3DDev->SetRenderState(D3DRS_ZENABLE, TRUE); return true; }
I have no idea what I am missing. Before I tried cleaning the code up, and putting the data into one struct, and putting the code into a class it was working wonderfully.
Any assistance would be greatly appreciated. Thank you.
If you need to know anything else, just let me know.


